<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.16"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>LibTools: H:/project/LibTools/src/ipc/internal/IpcSocket.cpp 源文件</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">LibTools
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- 制作者 Doxygen 1.8.16 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',false,false,'search.php','搜索');
});
/* @license-end */</script>
<div id="main-nav"></div>
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li><li class="navelem"><a class="el" href="dir_b94456e2763cc4ff61641ee1fd517631.html">ipc</a></li><li class="navelem"><a class="el" href="dir_08f7e595e04b6b21bd129111ec77a9cc.html">internal</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">IpcSocket.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_ipc_socket_8cpp.html">浏览该文件的文档.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="_ipc_socket_8h.html">IpcSocket.h</a>&quot;</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="preprocessor">#include &quot;../../socket/internal/SockData.h&quot;</span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="preprocessor">#include &quot;../../algorithm/Algorithm.h&quot;</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="preprocessor">#include &quot;../../tools/ShareApi.h&quot;</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160; </div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<a class="code" href="tools_8h.html#a201ce692c9dca6599e5c12d00167419b">DEF_BEG_LIBTOOLS</a></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160; </div>
<div class="line"><a name="l00008"></a><span class="lineno"><a class="line" href="class_c_ipc_socket.html#abdd53375a7f44cc99f488d52bb1d0bec">    8</a></span>&#160;<a class="code" href="class_c_ipc_socket.html#abdd53375a7f44cc99f488d52bb1d0bec">CIpcSocket::CIpcSocket</a>()</div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;{</div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160; </div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;}</div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160; </div>
<div class="line"><a name="l00013"></a><span class="lineno"><a class="line" href="class_c_ipc_socket.html#a84f0b8ad9091be5242d5fd443173824a">   13</a></span>&#160;<a class="code" href="class_c_ipc_socket.html#abdd53375a7f44cc99f488d52bb1d0bec">CIpcSocket::CIpcSocket</a>(<a class="code" href="class_c_basic_service.html">CBasicService</a>* pServer) :<a class="code" href="class_c_socket.html">CSocket</a>(pServer)</div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;{</div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;}</div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160; </div>
<div class="line"><a name="l00017"></a><span class="lineno"><a class="line" href="class_c_ipc_socket.html#aa51689972d420888eaa68f71487e0f4e">   17</a></span>&#160;<a class="code" href="class_c_ipc_socket.html#aa51689972d420888eaa68f71487e0f4e">CIpcSocket::~CIpcSocket</a>()</div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;{</div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;}</div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160; </div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="preprocessor">#ifdef STD11</span></div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<a class="code" href="class_c_ipc_socket.html#abdd53375a7f44cc99f488d52bb1d0bec">CIpcSocket::CIpcSocket</a>(<a class="code" href="class_c_ipc_socket.html">CIpcSocket</a>&amp;&amp; sock) :<a class="code" href="class_c_socket.html">CSocket</a>()</div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;{</div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;    <a class="code" href="class_c_ipc_socket.html#adc077262c1ed1ced2398779c17f6cc05">_Close</a>();</div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;    <a class="code" href="class_c_ipc_socket.html#ac1383f482c53e9b95735a9b2eef63ee3">Swap</a>(sock);</div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;}</div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160; </div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;<a class="code" href="class_c_ipc_socket.html">CIpcSocket</a>&amp; CIpcSocket::operator= (<a class="code" href="class_c_ipc_socket.html">CIpcSocket</a>&amp;&amp; sock)</div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;{</div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;    <span class="keywordflow">if</span> (<span class="keyword">this</span> != &amp;sock)</div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;    {</div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;        <a class="code" href="class_c_socket.html#aa915ac02c07eed947bf2da35eacc3545">Close</a>();</div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;        <a class="code" href="class_c_ipc_socket.html#ac1383f482c53e9b95735a9b2eef63ee3">Swap</a>(sock);</div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;    }</div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;    <span class="keywordflow">return</span> *<span class="keyword">this</span>;</div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;}</div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;<span class="preprocessor">#endif // STD11</span></div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160; </div>
<div class="line"><a name="l00039"></a><span class="lineno"><a class="line" href="class_c_ipc_socket.html#ac1383f482c53e9b95735a9b2eef63ee3">   39</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="class_c_ipc_socket.html#ac1383f482c53e9b95735a9b2eef63ee3">CIpcSocket::Swap</a>(<a class="code" href="class_c_ipc_socket.html">CIpcSocket</a>&amp; sock)</div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;{</div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;    <span class="keywordflow">if</span> (<span class="keyword">this</span> != &amp;sock)</div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;    {</div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;        dynamic_cast&lt;CSocket*&gt;(<span class="keyword">this</span>)-&gt;Swap(*(dynamic_cast&lt;CSocket*&gt;(&amp;sock)));</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;        this-&gt;<a class="code" href="class_c_ipc_socket.html#ac1383f482c53e9b95735a9b2eef63ee3">Swap</a>(sock);</div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;    }</div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;}</div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160; </div>
<div class="line"><a name="l00048"></a><span class="lineno"><a class="line" href="class_c_ipc_socket.html#ad954cee189b57a0bb1ff5c95c25de871">   48</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="class_c_ipc_socket.html#ad954cee189b57a0bb1ff5c95c25de871">CIpcSocket::SetAddr</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* name)</div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;{</div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;<span class="preprocessor">#ifdef WIN32</span></div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;    <span class="keywordflow">if</span> (strncmp(name, <span class="stringliteral">&quot;\\\\.\\pipe\\&quot;</span>, 9) != 0) </div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;    {</div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;        std::string pipName = <span class="stringliteral">&quot;\\\\.\\pipe\\&quot;</span>;</div>
<div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;        pipName += name;</div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;        <a class="code" href="class_c_socket.html#afaa6fee02d3a38224445cb42d63d3521">CSocket::SetAddr</a>(pipName.data());</div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;    }</div>
<div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;    <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;        <a class="code" href="class_c_socket.html#afaa6fee02d3a38224445cb42d63d3521">CSocket::SetAddr</a>(name);</div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;    }</div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;<span class="preprocessor">#elif defined(LINUX)</span></div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;    <span class="keywordflow">if</span> (strrchr(name, <span class="charliteral">&#39;/&#39;</span>) == <a class="code" href="tools_8h.html#ab689500aaec0db066e3ac9483d3fe425">NullPtr</a>) </div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;    {</div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;        <span class="keywordtype">char</span> curPath[<a class="code" href="tools_8h.html#ab99ded389af74001a6298fc9e44e74e5">MAX_PATH</a>];</div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;        <a class="code" href="namespace_share_api.html#a4e74675c3ae4e3233eeeb2088057aca8">ShareApi::GetCurrentDirectory</a>(<span class="keyword">sizeof</span>(curPath), curPath);</div>
<div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;        std::string uxPath = curPath; uxPath += <span class="charliteral">&#39;/&#39;</span>; uxPath += name;</div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;        <a class="code" href="class_c_socket.html#afaa6fee02d3a38224445cb42d63d3521">CSocket::SetAddr</a>(uxPath.c_str());</div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;    }</div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;    <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;        <a class="code" href="class_c_socket.html#afaa6fee02d3a38224445cb42d63d3521">CSocket::SetAddr</a>(name);</div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;    }</div>
<div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;}</div>
<div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160; </div>
<div class="line"><a name="l00074"></a><span class="lineno"><a class="line" href="class_c_ipc_socket.html#a98690fd3fe7a16b71852b4dce797e4f7">   74</a></span>&#160;<a class="code" href="class_c_sock_error.html">CSockError</a> <a class="code" href="class_c_ipc_socket.html#a98690fd3fe7a16b71852b4dce797e4f7">CIpcSocket::WaitNamedPipe</a>(<a class="code" href="tools_8h.html#a798af1e30bc65f319c1a246cecf59e39">DWORD</a> timeout)<span class="keyword"> const</span></div>
<div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;<span class="keyword"></span>{</div>
<div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;    <a class="code" href="class_c_sock_error.html">CSockError</a> ec;</div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;<span class="preprocessor">#ifdef WIN32</span></div>
<div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;    <span class="keywordflow">if</span> (::WaitNamedPipeA(<a class="code" href="class_c_socket.html#adc23006ccfd784a08cbfd2a9c0d3c85e">GetAddr</a>().c_str(), timeout) == <a class="code" href="tools_8h.html#aa93f0eb578d23995850d61f7d61c55c1">FALSE</a>)</div>
<div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;        ec.SetError(CSockError::SYS_ERROR);</div>
<div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;    <span class="keywordflow">return</span> ec;</div>
<div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;}</div>
<div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160; </div>
<div class="line"><a name="l00084"></a><span class="lineno"><a class="line" href="class_c_ipc_socket.html#a910a50405e2de5f9f214af218b25519c">   84</a></span>&#160;<a class="code" href="class_c_sock_error.html">CSockError</a> <a class="code" href="class_c_ipc_socket.html#a910a50405e2de5f9f214af218b25519c">CIpcSocket::Socket</a>(<a class="code" href="namespace_s_o_c_k_f_a_m_i_l_y.html#a2752d06098f227dbd8340b30a718da81">SOCKFAMILY::SockFamily</a> domain <span class="comment">/* = SOCKFAMILY::IPC */</span>, <a class="code" href="namespace_s_o_c_k_t_y_p_e.html#ab1b532206487defe92ed4eeae94b488c">SOCKTYPE::SockType</a> type <span class="comment">/* = SOCKTYPE::STREAM */</span>,</div>
<div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;    <a class="code" href="namespace_s_o_c_k_p_r_o_t_o_c_o_l.html#a6fcb9a12773185f3ca183ad967bb672e">SOCKPROTOCOL::SockProtocol</a> protocol <span class="comment">/* = SOCKPROTOCOL::IPC_OPEN */</span>)</div>
<div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;{</div>
<div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;    <a class="code" href="class_c_sock_error.html">CSockError</a> ec(CSockError::SUCC);</div>
<div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;    <a class="code" href="class_c_socket.html#a630790930bc708f198f90181420892a5">SetProtocol</a>(protocol);</div>
<div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;    <a class="code" href="class_c_socket.html#ab0833e2e82bcca3a85057fcecb2287bb">SetSockType</a>(type);</div>
<div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;    <a class="code" href="class_c_socket.html#aafc3fc3ab0c1e3d5ae2cf9dfba46d442">SetDomain</a>(domain);</div>
<div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;<span class="preprocessor">#ifdef WIN32</span></div>
<div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;    <span class="keywordflow">if</span> (protocol == <a class="code" href="namespace_s_o_c_k_p_r_o_t_o_c_o_l.html#a6fcb9a12773185f3ca183ad967bb672ea43d9e1a8ae64989aa870537a77c1fa8e">SOCKPROTOCOL::IPC_CREATE</a>)</div>
<div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;    {</div>
<div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;        <a class="code" href="tools_8h.html#a798af1e30bc65f319c1a246cecf59e39">DWORD</a> dwMode = 0;</div>
<div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;        <span class="keywordflow">if</span> (type == <a class="code" href="namespace_s_o_c_k_t_y_p_e.html#ab1b532206487defe92ed4eeae94b488ca6c4816da2ab72fec5773dc4650d5aa78">SOCKTYPE::DGRAM</a>) dwMode = PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE;</div>
<div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;        <span class="keywordflow">else</span> dwMode = PIPE_TYPE_BYTE | PIPE_TYPE_MESSAGE;</div>
<div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;        dwMode |= PIPE_WAIT;</div>
<div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;        <a class="code" href="tools_8h.html#ab521aa5010fb1afb801a899a55569e03">HANDLE</a> pip = CreateNamedPipeA(<a class="code" href="class_c_socket.html#adc23006ccfd784a08cbfd2a9c0d3c85e">GetAddr</a>().c_str(), PIPE_ACCESS_DUPLEX|FILE_FLAG_OVERLAPPED, dwMode, PIPE_UNLIMITED_INSTANCES, 65536, 65536, 0, <a class="code" href="tools_8h.html#ab689500aaec0db066e3ac9483d3fe425">NullPtr</a>);</div>
<div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;        <span class="keywordflow">if</span>(pip == INVALID_HANDLE_VALUE) ec.SetError(CSockError::SYS_ERROR);</div>
<div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;        <a class="code" href="class_c_socket.html#aaa6d7615fa3799b3b2ddba01f4dcc675">SetSocket</a>((<a class="code" href="tools_8h.html#aff55fe551a9992a54ec54621c524d0a4">SOCKET</a>)pip);</div>
<div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;    }</div>
<div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;    <span class="keywordflow">else</span></div>
<div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;    {</div>
<div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;        <a class="code" href="tools_8h.html#ab521aa5010fb1afb801a899a55569e03">HANDLE</a> pip = CreateFileA(<a class="code" href="class_c_socket.html#adc23006ccfd784a08cbfd2a9c0d3c85e">GetAddr</a>().c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, <a class="code" href="tools_8h.html#ab689500aaec0db066e3ac9483d3fe425">NullPtr</a>, </div>
<div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;            OPEN_ALWAYS, FILE_FLAG_OVERLAPPED, <a class="code" href="tools_8h.html#ab689500aaec0db066e3ac9483d3fe425">NullPtr</a>);</div>
<div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;        <span class="keywordflow">if</span> (pip == INVALID_HANDLE_VALUE) ec.SetError(CSockError::SYS_ERROR);</div>
<div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;        <a class="code" href="class_c_socket.html#aaa6d7615fa3799b3b2ddba01f4dcc675">SetSocket</a>((<a class="code" href="tools_8h.html#aff55fe551a9992a54ec54621c524d0a4">SOCKET</a>)pip);</div>
<div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;    }</div>
<div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;<span class="preprocessor">#elif defined(LINUX)</span></div>
<div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;    <span class="keywordtype">int</span> s = socket(AF_UNIX, type, 0);</div>
<div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;    <span class="keywordflow">if</span> (s == -1) ec.SetSysError(CSockError::SYS_ERROR);</div>
<div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;    <a class="code" href="class_c_socket.html#aaa6d7615fa3799b3b2ddba01f4dcc675">SetSocket</a>(s);</div>
<div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;    </div>
<div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;    <span class="keywordflow">return</span> ec;</div>
<div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;}</div>
<div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160; </div>
<div class="line"><a name="l00118"></a><span class="lineno"><a class="line" href="class_c_ipc_socket.html#a26096a3ca407eb22869be8d6ec6b13a1">  118</a></span>&#160;<a class="code" href="class_c_sock_error.html">CSockError</a> <a class="code" href="class_c_ipc_socket.html#a26096a3ca407eb22869be8d6ec6b13a1">CIpcSocket::SetNolock</a>()</div>
<div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;{</div>
<div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;<span class="preprocessor">#ifdef WIN32</span></div>
<div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="class_c_sock_error.html">CSockError</a>(CSockError::SUCC);</div>
<div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;<span class="preprocessor">#elif defined(LINUX)</span></div>
<div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="class_c_socket.html#a3f8d60c59caa235c4fb603e269166fd4">CSocket::SetNolock</a>();</div>
<div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;}</div>
<div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160; </div>
<div class="line"><a name="l00127"></a><span class="lineno"><a class="line" href="class_c_ipc_socket.html#adc077262c1ed1ced2398779c17f6cc05">  127</a></span>&#160;<span class="keywordtype">int</span> <a class="code" href="class_c_ipc_socket.html#adc077262c1ed1ced2398779c17f6cc05">CIpcSocket::_Close</a>()</div>
<div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;{</div>
<div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;<span class="preprocessor">#ifdef WIN32</span></div>
<div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;    <a class="code" href="tools_8h.html#ac3247c51e4e3de674affb32998e133e2">BOOL</a> b1, b2;</div>
<div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;    <span class="keywordflow">if</span> (*<a class="code" href="class_c_socket.html#abfcf493607b9c1b40db907d89731d4a9">GetSockPtr</a>() != <a class="code" href="tools_8h.html#a26769957ec1a2beaf223f33b66ee64ab">INVALID_SOCKET</a>)</div>
<div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;    {</div>
<div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;        b1 = ::DisconnectNamedPipe((<a class="code" href="tools_8h.html#ab521aa5010fb1afb801a899a55569e03">HANDLE</a>)*<a class="code" href="class_c_socket.html#abfcf493607b9c1b40db907d89731d4a9">GetSockPtr</a>());</div>
<div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;        b2 = ::CloseHandle((<a class="code" href="tools_8h.html#ab521aa5010fb1afb801a899a55569e03">HANDLE</a>)*<a class="code" href="class_c_socket.html#abfcf493607b9c1b40db907d89731d4a9">GetSockPtr</a>());</div>
<div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;        <a class="code" href="class_c_socket.html#aaa6d7615fa3799b3b2ddba01f4dcc675">SetSocket</a>(<a class="code" href="tools_8h.html#a26769957ec1a2beaf223f33b66ee64ab">INVALID_SOCKET</a>);</div>
<div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;    }</div>
<div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;    <span class="keywordflow">if</span> (b1 == <a class="code" href="tools_8h.html#aa93f0eb578d23995850d61f7d61c55c1">FALSE</a> || b2 == <a class="code" href="tools_8h.html#aa93f0eb578d23995850d61f7d61c55c1">FALSE</a>) <span class="keywordflow">return</span> -1;</div>
<div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160; </div>
<div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;    <span class="keywordflow">return</span> 0;</div>
<div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;<span class="preprocessor">#elif defined(LINUX)</span></div>
<div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="class_c_socket.html#a18f281b53430ae6e741ac65c08ff42e2">CSocket::_Close</a>();</div>
<div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;}</div>
<div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160; </div>
<div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;<a class="code" href="tools_8h.html#ac909db71799bb22cb7d636a34cd785e4">DEF_END_LIBTOOLS</a></div>
</div><!-- fragment --></div><!-- contents -->
<div class="ttc" id="aclass_c_ipc_socket_html_a910a50405e2de5f9f214af218b25519c"><div class="ttname"><a href="class_c_ipc_socket.html#a910a50405e2de5f9f214af218b25519c">CIpcSocket::Socket</a></div><div class="ttdeci">virtual CSockError Socket(SOCKFAMILY::SockFamily domain=SOCKFAMILY::IPC, SOCKTYPE::SockType type=SOCKTYPE::STREAM, SOCKPROTOCOL::SockProtocol protocol=SOCKPROTOCOL::IPC_OPEN)</div><div class="ttdoc">初始化套接字</div><div class="ttdef"><b>Definition:</b> <a href="_ipc_socket_8cpp_source.html#l00084">IpcSocket.cpp:84</a></div></div>
<div class="ttc" id="aclass_c_sock_error_html"><div class="ttname"><a href="class_c_sock_error.html">CSockError</a></div><div class="ttdoc">套接字错误信息类</div><div class="ttdef"><b>Definition:</b> <a href="_sock_error_8h_source.html#l00013">SockError.h:13</a></div></div>
<div class="ttc" id="aclass_c_socket_html_afaa6fee02d3a38224445cb42d63d3521"><div class="ttname"><a href="class_c_socket.html#afaa6fee02d3a38224445cb42d63d3521">CSocket::SetAddr</a></div><div class="ttdeci">virtual void SetAddr(const char *addr)</div><div class="ttdoc">设置远程或本地地址</div><div class="ttdef"><b>Definition:</b> <a href="_socket_8cpp_source.html#l00171">Socket.cpp:171</a></div></div>
<div class="ttc" id="atools_8h_html_a26769957ec1a2beaf223f33b66ee64ab"><div class="ttname"><a href="tools_8h.html#a26769957ec1a2beaf223f33b66ee64ab">INVALID_SOCKET</a></div><div class="ttdeci">#define INVALID_SOCKET</div><div class="ttdef"><b>Definition:</b> <a href="tools_8h_source.html#l00215">tools.h:215</a></div></div>
<div class="ttc" id="aclass_c_ipc_socket_html_a26096a3ca407eb22869be8d6ec6b13a1"><div class="ttname"><a href="class_c_ipc_socket.html#a26096a3ca407eb22869be8d6ec6b13a1">CIpcSocket::SetNolock</a></div><div class="ttdeci">virtual CSockError SetNolock()</div><div class="ttdoc">设置非阻塞</div><div class="ttdef"><b>Definition:</b> <a href="_ipc_socket_8cpp_source.html#l00118">IpcSocket.cpp:118</a></div></div>
<div class="ttc" id="aclass_c_socket_html_aafc3fc3ab0c1e3d5ae2cf9dfba46d442"><div class="ttname"><a href="class_c_socket.html#aafc3fc3ab0c1e3d5ae2cf9dfba46d442">CSocket::SetDomain</a></div><div class="ttdeci">virtual void SetDomain(SOCKFAMILY::SockFamily domain=SOCKFAMILY::IPV4)</div><div class="ttdoc">设置协议族,注意重置该值将会清空地址、端口信息</div><div class="ttdef"><b>Definition:</b> <a href="_socket_8cpp_source.html#l00181">Socket.cpp:181</a></div></div>
<div class="ttc" id="anamespace_s_o_c_k_t_y_p_e_html_ab1b532206487defe92ed4eeae94b488ca6c4816da2ab72fec5773dc4650d5aa78"><div class="ttname"><a href="namespace_s_o_c_k_t_y_p_e.html#ab1b532206487defe92ed4eeae94b488ca6c4816da2ab72fec5773dc4650d5aa78">SOCKTYPE::DGRAM</a></div><div class="ttdoc">socket 数据报,暂时不支持</div><div class="ttdef"><b>Definition:</b> <a href="_socket_def_8h_source.html#l00048">SocketDef.h:48</a></div></div>
<div class="ttc" id="anamespace_s_o_c_k_p_r_o_t_o_c_o_l_html_a6fcb9a12773185f3ca183ad967bb672ea43d9e1a8ae64989aa870537a77c1fa8e"><div class="ttname"><a href="namespace_s_o_c_k_p_r_o_t_o_c_o_l.html#a6fcb9a12773185f3ca183ad967bb672ea43d9e1a8ae64989aa870537a77c1fa8e">SOCKPROTOCOL::IPC_CREATE</a></div><div class="ttdoc">创建IPC，当作为服务端连接时使用（仅CIpcSocket使用）</div><div class="ttdef"><b>Definition:</b> <a href="_socket_def_8h_source.html#l00034">SocketDef.h:34</a></div></div>
<div class="ttc" id="anamespace_s_o_c_k_p_r_o_t_o_c_o_l_html_a6fcb9a12773185f3ca183ad967bb672e"><div class="ttname"><a href="namespace_s_o_c_k_p_r_o_t_o_c_o_l.html#a6fcb9a12773185f3ca183ad967bb672e">SOCKPROTOCOL::SockProtocol</a></div><div class="ttdeci">SockProtocol</div><div class="ttdef"><b>Definition:</b> <a href="_socket_def_8h_source.html#l00031">SocketDef.h:31</a></div></div>
<div class="ttc" id="anamespace_s_o_c_k_t_y_p_e_html_ab1b532206487defe92ed4eeae94b488c"><div class="ttname"><a href="namespace_s_o_c_k_t_y_p_e.html#ab1b532206487defe92ed4eeae94b488c">SOCKTYPE::SockType</a></div><div class="ttdeci">SockType</div><div class="ttdef"><b>Definition:</b> <a href="_socket_def_8h_source.html#l00045">SocketDef.h:45</a></div></div>
<div class="ttc" id="aclass_c_socket_html_a18f281b53430ae6e741ac65c08ff42e2"><div class="ttname"><a href="class_c_socket.html#a18f281b53430ae6e741ac65c08ff42e2">CSocket::_Close</a></div><div class="ttdeci">virtual int _Close()</div><div class="ttdef"><b>Definition:</b> <a href="_socket_8cpp_source.html#l00092">Socket.cpp:92</a></div></div>
<div class="ttc" id="atools_8h_html_a201ce692c9dca6599e5c12d00167419b"><div class="ttname"><a href="tools_8h.html#a201ce692c9dca6599e5c12d00167419b">DEF_BEG_LIBTOOLS</a></div><div class="ttdeci">#define DEF_BEG_LIBTOOLS</div><div class="ttdef"><b>Definition:</b> <a href="tools_8h_source.html#l00036">tools.h:36</a></div></div>
<div class="ttc" id="aclass_c_ipc_socket_html_ac1383f482c53e9b95735a9b2eef63ee3"><div class="ttname"><a href="class_c_ipc_socket.html#ac1383f482c53e9b95735a9b2eef63ee3">CIpcSocket::Swap</a></div><div class="ttdeci">void Swap(CIpcSocket &amp;sock)</div><div class="ttdoc">交换两个套接口类</div><div class="ttdef"><b>Definition:</b> <a href="_ipc_socket_8cpp_source.html#l00039">IpcSocket.cpp:39</a></div></div>
<div class="ttc" id="aclass_c_ipc_socket_html_a98690fd3fe7a16b71852b4dce797e4f7"><div class="ttname"><a href="class_c_ipc_socket.html#a98690fd3fe7a16b71852b4dce797e4f7">CIpcSocket::WaitNamedPipe</a></div><div class="ttdeci">virtual CSockError WaitNamedPipe(DWORD timeout) const</div><div class="ttdoc">为win32提供的一个等待管道连接的函数</div><div class="ttdef"><b>Definition:</b> <a href="_ipc_socket_8cpp_source.html#l00074">IpcSocket.cpp:74</a></div></div>
<div class="ttc" id="aclass_c_socket_html"><div class="ttname"><a href="class_c_socket.html">CSocket</a></div><div class="ttdoc">套接口类</div><div class="ttdef"><b>Definition:</b> <a href="_socket_8h_source.html#l00030">Socket.h:30</a></div></div>
<div class="ttc" id="aclass_c_ipc_socket_html_ad954cee189b57a0bb1ff5c95c25de871"><div class="ttname"><a href="class_c_ipc_socket.html#ad954cee189b57a0bb1ff5c95c25de871">CIpcSocket::SetAddr</a></div><div class="ttdeci">virtual void SetAddr(const char *name)</div><div class="ttdoc">设置管道名称、或者unix套接字名称</div><div class="ttdef"><b>Definition:</b> <a href="_ipc_socket_8cpp_source.html#l00048">IpcSocket.cpp:48</a></div></div>
<div class="ttc" id="aclass_c_socket_html_a3f8d60c59caa235c4fb603e269166fd4"><div class="ttname"><a href="class_c_socket.html#a3f8d60c59caa235c4fb603e269166fd4">CSocket::SetNolock</a></div><div class="ttdeci">virtual CSockError SetNolock()</div><div class="ttdoc">设置非阻塞</div><div class="ttdef"><b>Definition:</b> <a href="_socket_8cpp_source.html#l00231">Socket.cpp:231</a></div></div>
<div class="ttc" id="aclass_c_ipc_socket_html_adc077262c1ed1ced2398779c17f6cc05"><div class="ttname"><a href="class_c_ipc_socket.html#adc077262c1ed1ced2398779c17f6cc05">CIpcSocket::_Close</a></div><div class="ttdeci">virtual int _Close()</div><div class="ttdef"><b>Definition:</b> <a href="_ipc_socket_8cpp_source.html#l00127">IpcSocket.cpp:127</a></div></div>
<div class="ttc" id="atools_8h_html_ac909db71799bb22cb7d636a34cd785e4"><div class="ttname"><a href="tools_8h.html#ac909db71799bb22cb7d636a34cd785e4">DEF_END_LIBTOOLS</a></div><div class="ttdeci">#define DEF_END_LIBTOOLS</div><div class="ttdef"><b>Definition:</b> <a href="tools_8h_source.html#l00038">tools.h:38</a></div></div>
<div class="ttc" id="atools_8h_html_ab99ded389af74001a6298fc9e44e74e5"><div class="ttname"><a href="tools_8h.html#ab99ded389af74001a6298fc9e44e74e5">MAX_PATH</a></div><div class="ttdeci">#define MAX_PATH</div><div class="ttdef"><b>Definition:</b> <a href="tools_8h_source.html#l00149">tools.h:149</a></div></div>
<div class="ttc" id="atools_8h_html_ab521aa5010fb1afb801a899a55569e03"><div class="ttname"><a href="tools_8h.html#ab521aa5010fb1afb801a899a55569e03">HANDLE</a></div><div class="ttdeci">#define HANDLE</div><div class="ttdef"><b>Definition:</b> <a href="tools_8h_source.html#l00156">tools.h:156</a></div></div>
<div class="ttc" id="atools_8h_html_aa93f0eb578d23995850d61f7d61c55c1"><div class="ttname"><a href="tools_8h.html#aa93f0eb578d23995850d61f7d61c55c1">FALSE</a></div><div class="ttdeci">#define FALSE</div><div class="ttdef"><b>Definition:</b> <a href="tools_8h_source.html#l00148">tools.h:148</a></div></div>
<div class="ttc" id="a_ipc_socket_8h_html"><div class="ttname"><a href="_ipc_socket_8h.html">IpcSocket.h</a></div></div>
<div class="ttc" id="atools_8h_html_a798af1e30bc65f319c1a246cecf59e39"><div class="ttname"><a href="tools_8h.html#a798af1e30bc65f319c1a246cecf59e39">DWORD</a></div><div class="ttdeci">unsigned int DWORD</div><div class="ttdef"><b>Definition:</b> <a href="tools_8h_source.html#l00134">tools.h:134</a></div></div>
<div class="ttc" id="aclass_c_socket_html_aa915ac02c07eed947bf2da35eacc3545"><div class="ttname"><a href="class_c_socket.html#aa915ac02c07eed947bf2da35eacc3545">CSocket::Close</a></div><div class="ttdeci">virtual int Close()</div><div class="ttdoc">关闭套接字</div><div class="ttdef"><b>Definition:</b> <a href="_socket_8cpp_source.html#l00107">Socket.cpp:107</a></div></div>
<div class="ttc" id="aclass_c_socket_html_a630790930bc708f198f90181420892a5"><div class="ttname"><a href="class_c_socket.html#a630790930bc708f198f90181420892a5">CSocket::SetProtocol</a></div><div class="ttdeci">virtual void SetProtocol(SOCKPROTOCOL::SockProtocol protocol=SOCKPROTOCOL::TCP)</div><div class="ttdoc">设置协议类型</div><div class="ttdef"><b>Definition:</b> <a href="_socket_8cpp_source.html#l00188">Socket.cpp:188</a></div></div>
<div class="ttc" id="atools_8h_html_ac3247c51e4e3de674affb32998e133e2"><div class="ttname"><a href="tools_8h.html#ac3247c51e4e3de674affb32998e133e2">BOOL</a></div><div class="ttdeci">unsigned int BOOL</div><div class="ttdef"><b>Definition:</b> <a href="tools_8h_source.html#l00137">tools.h:137</a></div></div>
<div class="ttc" id="aclass_c_socket_html_abfcf493607b9c1b40db907d89731d4a9"><div class="ttname"><a href="class_c_socket.html#abfcf493607b9c1b40db907d89731d4a9">CSocket::GetSockPtr</a></div><div class="ttdeci">virtual SOCKET * GetSockPtr() const</div><div class="ttdoc">获取套接口句柄指针</div><div class="ttdef"><b>Definition:</b> <a href="_socket_8cpp_source.html#l00161">Socket.cpp:161</a></div></div>
<div class="ttc" id="atools_8h_html_ab689500aaec0db066e3ac9483d3fe425"><div class="ttname"><a href="tools_8h.html#ab689500aaec0db066e3ac9483d3fe425">NullPtr</a></div><div class="ttdeci">#define NullPtr</div><div class="ttdef"><b>Definition:</b> <a href="tools_8h_source.html#l00119">tools.h:119</a></div></div>
<div class="ttc" id="aclass_c_socket_html_aaa6d7615fa3799b3b2ddba01f4dcc675"><div class="ttname"><a href="class_c_socket.html#aaa6d7615fa3799b3b2ddba01f4dcc675">CSocket::SetSocket</a></div><div class="ttdeci">virtual void SetSocket(SOCKET sock)</div><div class="ttdoc">设置套接字描述符</div><div class="ttdef"><b>Definition:</b> <a href="_socket_8cpp_source.html#l00176">Socket.cpp:176</a></div></div>
<div class="ttc" id="aclass_c_socket_html_ab0833e2e82bcca3a85057fcecb2287bb"><div class="ttname"><a href="class_c_socket.html#ab0833e2e82bcca3a85057fcecb2287bb">CSocket::SetSockType</a></div><div class="ttdeci">virtual void SetSockType(SOCKTYPE::SockType type=SOCKTYPE::STREAM)</div><div class="ttdoc">设置套接字发送类型</div><div class="ttdef"><b>Definition:</b> <a href="_socket_8cpp_source.html#l00193">Socket.cpp:193</a></div></div>
<div class="ttc" id="atools_8h_html_aff55fe551a9992a54ec54621c524d0a4"><div class="ttname"><a href="tools_8h.html#aff55fe551a9992a54ec54621c524d0a4">SOCKET</a></div><div class="ttdeci">#define SOCKET</div><div class="ttdef"><b>Definition:</b> <a href="tools_8h_source.html#l00217">tools.h:217</a></div></div>
<div class="ttc" id="aclass_c_socket_html_adc23006ccfd784a08cbfd2a9c0d3c85e"><div class="ttname"><a href="class_c_socket.html#adc23006ccfd784a08cbfd2a9c0d3c85e">CSocket::GetAddr</a></div><div class="ttdeci">virtual std::string GetAddr() const</div><div class="ttdoc">获取连接或绑定的地址</div><div class="ttdef"><b>Definition:</b> <a href="_socket_8cpp_source.html#l00213">Socket.cpp:213</a></div></div>
<div class="ttc" id="aclass_c_ipc_socket_html_aa51689972d420888eaa68f71487e0f4e"><div class="ttname"><a href="class_c_ipc_socket.html#aa51689972d420888eaa68f71487e0f4e">CIpcSocket::~CIpcSocket</a></div><div class="ttdeci">virtual ~CIpcSocket()</div><div class="ttdef"><b>Definition:</b> <a href="_ipc_socket_8cpp_source.html#l00017">IpcSocket.cpp:17</a></div></div>
<div class="ttc" id="aclass_c_basic_service_html"><div class="ttname"><a href="class_c_basic_service.html">CBasicService</a></div><div class="ttdoc">服务类 基类</div><div class="ttdef"><b>Definition:</b> <a href="_service_base_8h_source.html#l00015">ServiceBase.h:15</a></div></div>
<div class="ttc" id="anamespace_share_api_html_a4e74675c3ae4e3233eeeb2088057aca8"><div class="ttname"><a href="namespace_share_api.html#a4e74675c3ae4e3233eeeb2088057aca8">ShareApi::GetCurrentDirectory</a></div><div class="ttdeci">LIBTOOLS BOOL GetCurrentDirectory(DWORD size, TCHAR *szPath)</div><div class="ttdoc">获取当前进程目录</div><div class="ttdef"><b>Definition:</b> <a href="_share_api_8cpp_source.html#l00485">ShareApi.cpp:485</a></div></div>
<div class="ttc" id="aclass_c_ipc_socket_html_abdd53375a7f44cc99f488d52bb1d0bec"><div class="ttname"><a href="class_c_ipc_socket.html#abdd53375a7f44cc99f488d52bb1d0bec">CIpcSocket::CIpcSocket</a></div><div class="ttdeci">CIpcSocket()</div><div class="ttdef"><b>Definition:</b> <a href="_ipc_socket_8cpp_source.html#l00008">IpcSocket.cpp:8</a></div></div>
<div class="ttc" id="aclass_c_ipc_socket_html"><div class="ttname"><a href="class_c_ipc_socket.html">CIpcSocket</a></div><div class="ttdoc">ipc通信专用套接字</div><div class="ttdef"><b>Definition:</b> <a href="_ipc_socket_8h_source.html#l00010">IpcSocket.h:10</a></div></div>
<div class="ttc" id="anamespace_s_o_c_k_f_a_m_i_l_y_html_a2752d06098f227dbd8340b30a718da81"><div class="ttname"><a href="namespace_s_o_c_k_f_a_m_i_l_y.html#a2752d06098f227dbd8340b30a718da81">SOCKFAMILY::SockFamily</a></div><div class="ttdeci">SockFamily</div><div class="ttdef"><b>Definition:</b> <a href="_socket_def_8h_source.html#l00057">SocketDef.h:57</a></div></div>
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
制作者 &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.16
</small></address>
</body>
</html>
